package com.zaoniao.enstudy.infracore.web;

import com.github.pagehelper.PageInfo;
import lombok.Data;

import java.util.List;

/**
 * 用来返回分页Grid的数据格式.
 *
 * @author llb
 */
@Data
public class PagedGridResult<T> {

    /**
     * 当前页数
     */
    private int page;

    /**
     * 总页数
     */
    private int total;

    /**
     * 总记录数
     */
    private long records;

    /**
     * 每行显示的内容
     */
    private List<T> rows;

    public static <T> PagedGridResult<T> setterPagedGrid(List<T> list) {
        PageInfo<T> pageInfo = new PageInfo<>(list);
        PagedGridResult<T> grid = new PagedGridResult<>();
        grid.setPage(pageInfo.getPageNum());
        grid.setTotal(pageInfo.getPages());
        grid.setRecords(pageInfo.getTotal());
        grid.setRows(pageInfo.getList());
        return grid;
    }

}
